#pragma once
#include <boost\asio\io_service.hpp>
#include <boost\asio\serial_port.hpp>
#include <boost\shared_ptr.hpp>
#include <boost\unordered_map.hpp>
#include <boost\thread\mutex.hpp>

#include "SerialPortInfo.h"
#include "types.h"

typedef boost::shared_ptr<SerialPortInfo> SerialPortInfoPtr;

class SerialPortFactory
{
	boost::shared_ptr<worker> ios_worker;
	boost::shared_ptr<io_service> ios;
	boost::unordered_map<const __int64, SerialPortInfoPtr> map;
	boost::mutex lock;
public:
	SerialPortFactory();
	~SerialPortFactory();

	void init();

	void close();

	void run();
	
	std::size_t run_one(boost::system::error_code & ec);

	io_service_ptr get_ios_ptr() { return ios; }

	void insert_serial_info(const __int64 fd, SerialPortInfoPtr serialPortInfo);

	void remove_serial_info(const __int64 fd);

	SerialPortInfoPtr get_serial_info(const __int64 fd);

	void uninit();
};

